package com.shengde.jinwawaforleader.model.homePage;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.shengde.jinwawaforleader.R;
import com.shengde.jinwawaforleader.base.BaseActivity;
import com.shengde.jinwawaforleader.bean.User;
import com.shengde.jinwawaforleader.network.BaseProtocol;
import com.shengde.jinwawaforleader.network.protocolbean.ProVideoShowClickGood;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 找回密码页面
 * Created by Administrator on 2016/11/24 0024.
 */
public class FindPasswordActivity extends BaseActivity {

	private TextView tv_back;
	private TextView tv_title;
	private TextView tv_password_prompt;  //设置密码提示
	private Button btn_next;
	private EditText edt_num;  //输入的手机号码
	private RelativeLayout relative_password;

	@Override
	public void onRoot(Bundle savedInstanceState) {
		setContentView(R.layout.find_password_activity);
	}

	@Override
	public void initView() {
		tv_back = (TextView) findViewById(R.id.tv_back);
		tv_title = (TextView) findViewById(R.id.tv_title);
		edt_num = (EditText) findViewById(R.id.edt_num);
		tv_password_prompt = (TextView) findViewById(R.id.tv_password_prompt);
		relative_password = (RelativeLayout) findViewById(R.id.relative_password);
		btn_next = (Button) findViewById(R.id.btn_next);

	}

	@Override
	public void initData() {
		tv_password_prompt.setVisibility(View.GONE);
		relative_password.setVisibility(View.GONE);
		tv_title.setText(getString(R.string.find_password));

	}

	@Override
	public void initListener() {
		tv_back.setOnClickListener(this);
		btn_next.setOnClickListener(this);
	}

	/**
	 * 判断电话号码是否符合格式.
	 *
	 * @param inputText the input text
	 * @return true, if is phone
	 */
	public static boolean isCorrectPhone(String inputText) {
		Pattern p = Pattern.compile("^((14[0-9])|(13[0-9])|(15[0-9])|(18[0-9])|(17[0-9]))\\d{8}$");
		Matcher m = p.matcher(inputText);
		return m.matches();
	}

	@Override
	public void onWidgetClick(View view) {
		switch (view.getId()) {
			case R.id.tv_back:
				finish();
				break;
			case R.id.btn_next:
				if (TextUtils.isEmpty(edt_num.getText().toString().trim())) {
					Toast.makeText(this, getString(R.string.telephone_not_empty), Toast.LENGTH_SHORT).show();
					return;
				} else if (!isCorrectPhone(edt_num.getText().toString().trim())) {
					Toast.makeText(this, getString(R.string.telephone_not_exist), Toast.LENGTH_SHORT).show();
					return;
				} else {
					Intent intent = new Intent(this, WriteAuthCodeActivity.class);
					intent.putExtra("telephone_num", edt_num.getText().toString().toString());
					startActivity(intent);

				}
				break;
		}
	}

}
